﻿Imports System.Xml

Public Class TextFrame
	Inherits Child

	Public Overrides Function ToString() As String
		Return "TextFrame" & Me.Self
	End Function

	Property PathGeometry As PathGeometry

	Property Self As String

	Property Name As String

	Property ParentStory As String

	Property PreviousTextFrame As String

	Property NextTextFrame As String

	Property ContentType As ContentType

	Property StrokeWeight As Double?

	Property GradientFillStart As UnitPointType

	Property GradientFillLength As Double?

	Property GradientFillAngle As Double?

	Property GradientStrokeStart As UnitPointType

	Property GradientStrokeLength As Double?

	Property GradientStrokeAngle As Double?

	Property ItemLayer As String

	Property Locked As Nullable(Of Boolean)

	Property LocalDisplaySetting As DisplaySettingOptions?

	Property GradientFillHiliteLength As Double?

	Property GradientFillHiliteAngle As Double?

	Property GradientStrokeHiliteLength As Double?

	Property GradientStrokeHiliteAngle As Double?

	Property AppliedObjectStyle As String

	Property Visible As Boolean?

	Property ItemTransform As String

	Property TextFramePreference As TextFramePreference

	Property TextWrapPreference As TextWrapPreference

	Public Shared Function ReadXml(reader As XmlReader) As TextFrame
		Dim tf As New TextFrame()

		If reader.HasAttributes Then
			tf.Self = reader.GetAttribute("Self")
			tf.ParentStory = reader.GetAttribute("ParentStory")
			tf.PreviousTextFrame = reader.GetAttribute("PreviousTextFrame")
			tf.NextTextFrame = reader.GetAttribute("NextTextFrame")
			tf.ContentType = [Enum].Parse(GetType(ContentType), reader.GetAttribute("ContentType"))
			tf.StrokeWeight = Parser.ParseDouble(reader.GetAttribute("StrokeWeight"))
			tf.GradientFillStart = New UnitPointType(reader.GetAttribute("GradientFillStart"))
			tf.GradientFillLength = Parser.ParseDouble(reader.GetAttribute("GradientFillLength"))
			tf.GradientFillAngle = Parser.ParseDouble(reader.GetAttribute("GradientFillAngle"))
			tf.GradientStrokeStart = New UnitPointType(reader.GetAttribute("GradientStrokeStart"))
			tf.GradientStrokeLength = Parser.ParseDouble(reader.GetAttribute("GradientStrokeLength"))
			tf.GradientStrokeAngle = Parser.ParseDouble(reader.GetAttribute("GradientStrokeAngle"))
			tf.ItemLayer = reader.GetAttribute("ItemLayer")
			tf.Locked = Parser.ParseBoolean(reader.GetAttribute("Locked"))
			tf.LocalDisplaySetting = Parser.ParseEnum(Of DisplaySettingOptions)(reader.GetAttribute("LocalDisplaySetting"))
			tf.GradientFillHiliteLength = Parser.ParseDouble(reader.GetAttribute("GradientFillHiliteLength"))
			tf.GradientFillHiliteAngle = Parser.ParseDouble(reader.GetAttribute("GradientFillHiliteAngle"))
			tf.GradientStrokeHiliteLength = Parser.ParseDouble(reader.GetAttribute("GradientStrokeHiliteLength"))
			tf.GradientStrokeHiliteAngle = Parser.ParseDouble(reader.GetAttribute("GradientStrokeHiliteAngle"))
			tf.AppliedObjectStyle = reader.GetAttribute("AppliedObjectStyle")
			tf.Visible = Parser.ParseBoolean(reader.GetAttribute("Visible"))
			tf.Name = reader.GetAttribute("Name")
			tf.ItemTransform = reader.GetAttribute("ItemTransform")
		End If

		While reader.Read()
			Select Case reader.Name
				Case "Properties"
					While reader.Read()
						Select Case reader.Name
							Case "PathGeometry"
								tf.PathGeometry = PathGeometry.ReadXml(reader)
							Case "Properties"
								If reader.NodeType = XmlNodeType.EndElement Then Exit While
							Case Else
								If reader.NodeType = XmlNodeType.Element Then
									Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "TextFrame - Properties")
								End If
						End Select
					End While
				Case "TextFramePreference"
					tf.TextFramePreference = TextFramePreference.ReadXml(reader)
				Case "TextWrapPreference"
					tf.TextWrapPreference = TextWrapPreference.ReadXml(reader)
				Case "TextFrame"
					If reader.NodeType = XmlNodeType.EndElement Then Exit While
				Case Else
					If reader.NodeType = XmlNodeType.Element Then
						Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "TextFrame")
					End If
			End Select
		End While

		Return tf
	End Function
End Class